package com.baidu.aip.face;

import android.content.Context;
import android.graphics.RectF;
import android.os.Handler;
import android.os.Looper;
import android.util.AttributeSet;
import android.view.TextureView;

import androidx.annotation.Nullable;


/**
 * @author kzcai
 * @packageName com.baidu.aip.face
 * @date 2020-02-03
 */
public class HalfPreviewView extends TextureView implements PreviewView {
    private int videoWidth = 0;
    private int videoHeight = 0;
    private Handler handler = new Handler(Looper.getMainLooper());
    public HalfPreviewView( Context context) {
        super(context);
    }

    public HalfPreviewView( Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public HalfPreviewView( Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public TextureView getTextureView() {
        return this;
    }

    @Override
    public void setPreviewSize(int width, int height) {
        if (this.videoWidth == width && this.videoHeight == height) {
            return;
        }
        this.videoWidth = width;
        this.videoHeight = height;
        handler.post(new Runnable() {
            @Override
            public void run() {
                requestLayout();
            }
        });
    }

    @Override
    public void mapToOriginalRect(RectF rect) {

    }

    @Override
    public void mapFromOriginalRect(RectF rectF) {

    }

    @Override
    public void mapFromOriginalRectEx(RectF rectF) {

    }

    @Override
    public void setScaleType(ScaleType scaleType) {

    }

    @Override
    public ScaleType getScaleType() {
        return ScaleType.CROP_INSIDE;
    }
}
